package com.tongyi.lizhishop.activitys;

import android.os.Bundle;
import android.view.View;

import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.tongyi.lizhishop.api.UserApi;
import com.tongyi.lizhishop.beans.CommonResonseBean;
import com.tongyi.lizhishop.common.CommonObserver;

import com.tongyi.lizhishop.managers.APIServiceManager;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class ChangePhoneNumberActivity extends FindPasswordActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        titlebar.getCenterTextView().setText("修改手机");
        rightSecondTv.setVisibility(View.VISIBLE);
        rightTopTv.setVisibility(View.INVISIBLE);
        centerTopEt.setHint("请输入登录密码");
        centerSencondEt.setHint("请输入新手机号");
        centerThreeEt.setHint("请输入验证码");
        leftTopTv.setText("登录密码");
        leftSecondTv.setText("新手机号");
        leftThreeTv.setText("验证码");
    }

    @Override
    protected void submitData() {
        APIServiceManager.getInstance().create(UserApi.class)
                .changePhoneNumber(SPUtils.getInstance().getString("userid"), centerSencondEt.getText().toString(),
                        centerTopEt.getText().toString(), centerThreeEt.getText().toString())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new CommonObserver<CommonResonseBean>() {
                    @Override
                    public void onSuccess(CommonResonseBean value) {
                        if ("succ".equals(value.getRe())) {
                            ToastUtils.showLong("手机号修改成功!");
                            confirm.reset();
                            finish();
                        } else {
                            ToastUtils.showShort(value.getMsg());
                            confirm.reset();
                        }
                    }

                    @Override
                    public void onFailure(Throwable e) {

                    }
                });

    }
}
